package com.clinic.action.drugissue;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.clinic.action.common.AuthenticationAction;
import com.clinic.entity.gui.GuiPagination;
import com.clinic.entity.gui.GuiPrescription;
import com.clinic.entity.param.Index;
import com.clinic.logic.drugIssue.DrugIssueLogic;
import com.clinic.logic.prescription.PrescriptionLogic;
import com.clinic.util.CommonUtil;

public class DrugIssueAction extends AuthenticationAction {

	private static final long serialVersionUID = -6820544229316756299L;
	
	private int page = 1;
	private GuiPagination guiPagination;
	private long prescriptionId;
	private GuiPrescription guiPrescription;
	private List<GuiPrescription> guiPrescriptionList;
	
	@Autowired
	private PrescriptionLogic prescriptionLogic;
	@Autowired
	private DrugIssueLogic drugIssueLogic;
	
	public String list(){
		if(isDoctorLogin() || isAssistantLogin()) {
			Index index = CommonUtil.getIndexBypage(page);
			guiPrescriptionList = prescriptionLogic.getPrescriptions(index);
			guiPagination = prescriptionLogic.getPaginationOfPrescriptions(page);
			return ActionResult.SUCCESS;
		}
		return ActionResult.AUTH_FAILED;
	}
	
	public String show(){
		if(isDoctorLogin() || isAssistantLogin()) {
			guiPrescription = prescriptionLogic.getPrescriptionById(prescriptionId);
			return ActionResult.SUCCESS;
		}
		return ActionResult.AUTH_FAILED;
	}

	public String edit(){
		if(isDoctorLogin() || isAssistantLogin()) {
			guiPrescription = prescriptionLogic.getPrescriptionById(prescriptionId);
			return ActionResult.SUCCESS;
		}
		return ActionResult.AUTH_FAILED;
	}

	public String update(){
		if(isDoctorLogin() || isAssistantLogin()) {
			drugIssueLogic.updatePrescriptionDrugIssueList(guiPrescription.getPrescriptionId(), guiPrescription.getDrugIssueList());
			return ActionResult.SUCCESS;
		}
		return ActionResult.AUTH_FAILED;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public GuiPagination getGuiPagination() {
		return guiPagination;
	}

	public void setGuiPagination(GuiPagination guiPagination) {
		this.guiPagination = guiPagination;
	}

	public List<GuiPrescription> getGuiPrescriptionList() {
		return guiPrescriptionList;
	}

	public void setGuiPrescriptionList(List<GuiPrescription> guiPrescriptionList) {
		this.guiPrescriptionList = guiPrescriptionList;
	}

	public long getPrescriptionId() {
		return prescriptionId;
	}

	public void setPrescriptionId(long prescriptionId) {
		this.prescriptionId = prescriptionId;
	}

	public GuiPrescription getGuiPrescription() {
		return guiPrescription;
	}

	public void setGuiPrescription(GuiPrescription guiPrescription) {
		this.guiPrescription = guiPrescription;
	}

}
